﻿using System;
using System.Web.Mvc;
using ControleRepresentante.Logic.Models;
using ControleRepresentante.Logic.Repositories;
using ControleRepresentante.Logic.Statistics;
using WebSite.Controllers.ControllerExtensions;
using WebSite.ViewModels.DetailsViewModels;

namespace WebSite.Controllers
{
    public abstract class UsuariosHolderControllerBase<TRepository, TModel, TStatistics> : DetailsHolderControllerBase<TRepository, TModel, TStatistics>
        where TRepository : class, IUsuariosHolderRepository<TModel, TStatistics>
        where TModel : UsuariosHolder
        where TStatistics : IStatistics
    {
        protected UsuariosHolderControllerBase(IRepositoryProvider repositoryProvider, ISessionConfiguration sessionConfiguration, IControllerExtensionProvider controllerExtensionProvider)
            : base(repositoryProvider, sessionConfiguration, controllerExtensionProvider)
        {
        }

        public ActionResult AddUser(Guid id)
        {
            return RedirectToAction(CreateForActionName, "Usuario", new { id = id });
        }

        protected abstract string CreateForActionName { get; }

        protected sealed override DetailsHolderDetailsViewModel DoGetDetailsViewModel(TModel model)
        {
            UsuariosHolderDetailsViewModel usuariosHolderDetailsViewModel = DoGetUsuariosHolderDetailsViewModel(model);
            usuariosHolderDetailsViewModel.CanAddUser = HasPermission(ControleRepresentante.Logic.Models.Area.Usuarios, Operacao.Create);
            return usuariosHolderDetailsViewModel;
        }

        protected abstract UsuariosHolderDetailsViewModel DoGetUsuariosHolderDetailsViewModel(TModel model);
    }
}